"ui";

$ui.layout(
    <frame w="*" h="*" gravity="center" bg="#000000">
        <text gravity="center|center_horizontal"   marginBottom="20"   id="example"     text=""       textSize="50" textColor="#ffffff"/>
        <text gravity="center|center_horizontal"   marginLeft="-110"   marginTop="60"   id="battery_" text=""       textSize="15" textColor="#ffffff"/>
        <text gravity="center|center_horizontal"   marginLeft="100"    marginTop="60"   id="IsCa"     text=""       textSize="15" textColor="#ffffff"/>
        <text gravity="center|center horizontal"   marginBottom="70"   id="year_"    text=""       textSize="15" textColor="#ffffff"/>
        
    </frame>
);
setInterval(() => {

    let text = $ui.example.attr("gravity");

    if (text == "center|center_horizontal") {
        $ui.example.attr("gravity", "bottom|center_horizontal");
        $ui.battery_.attr("gravity", "bottom|center_horizontal");
        $ui.IsCa.attr("gravity", "bottom|center_horizontal");
        $ui.year_.attr("gravity", "bottom|center horizontal");
    }
    if (text == "bottom|center_horizontal") {
        $ui.example.attr("gravity", "top|center_horizontal");
        $ui.battery_.attr("gravity", "top|center_horizontal");
        $ui.IsCa.attr("gravity", "top|center_horizontal");
        $ui.year_.attr("gravity", "top|center horizontal");
    }
    if (text == "top|center_horizontal") {
        $ui.example.attr("gravity", "center|center_horizontal");
        $ui.battery_.attr("gravity", "center|center_horizontal");
        $ui.IsCa.attr("gravity", "center|center_horizontal");
        $ui.year_.attr("gravity", "center|center horizontal");
    }
}, 40 * 1000);
setTimeout(() => {}, 1000);
var ms, h, m, s, ms, years;

setInterval(() => {

    var Date_ = new Date();
    h = Date_.getHours();
    m = Date_.getMinutes();
    s = Date_.getSeconds();
    ms = Date_.getMilliseconds();
    if (h < 10) {
        h = "0" + h
    }
    if (m < 10) {
        m = "0" + m
    }
    if (s < 10) {
        s = "0" + s
    }
},1000);
var cnWeek = {
    0 : "零",
    1 : "一",
    2 : "二",
    3 : "三",
    4 : "四",
    5 : "五",
    6 : "六",
    7 : "日",
};
setInterval(() => {
    var Date_ = new Date();
    ms = Date_.getMilliseconds();
    if (ms < 10) {
        ms = "0" + ms
    }
    years = Date_.getFullYear();
    month = Date_.getMonth() + 1;
    days = Date_.getDate();
    week = Date_.getDay() + 1;
    var ms_ay = ms.toString();
    ms_str = ms_ay[0] + ms_ay[1];
    var ss = String(h) + ":" + String(m) + ":" + String(s) + ":" + String(ms_str);
    $ui.year_.attr("text", years + "年" +  month + "月" + days + "日" + "星期" +cnWeek[week]);
    $ui.example.attr("text", ss.toString());
    activity.window.addFlags(android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN);
}, 1)
device.keepScreenOn(3600 * 1000);
setInterval(() => {
    var Battery = device.getBattery().toFixed(0);
    var IsReCharing = device.isCharging();
    $ui.battery_.attr("text", "Battery:" + Battery.toString());
    var str;
    if (IsReCharing == true)
        str = "YES";
    else
        str = "NO"
    $ui.IsCa.attr("text", "Charge: " + str)
}, 10);